
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <sys/time.h>
#include "app_platform/cntl_info.h"
#include "app_platform/cgi_stub_cntl.h"
#include "../include/storagedao_stub4web_allinone.h"
#include <set>	
#include <map>	
#include <vector>	
#include "erp/storage/ddo/stockddo_storage.h"	
#include "erp/storage/ddo/stockfilterddo_storage.h"	

using namespace erp::storage::dao;

void Init()
{       
	if(CCGI_STUB_CNTL->Initialize(true) != 0)
		std::cerr << "CCGI_STUB_CNTL->Init failed" << std::endl;
	CCGI_STUB_CNTL->setTimeout(5);
}
void TestAddStock()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(8887);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(8887);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	uint32_t option = 0;
	erp::storage::ddo::CStockDdo StockInfo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	uint64_t SysNo = 0;
	CStorageDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.AddStock(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		option,
		StockInfo,
		inReserve,
		errmsg,
		outReserve,
		SysNo
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestDeleteStock()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(8887);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(8887);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	uint32_t option = 0;
	std::set<uint64_t > FStockSysNo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::map<uint64_t,uint32_t > errorCode;
	std::map<uint64_t,std::string > errorMsg;
	std::string outReserve = "";		
	CStorageDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.DeleteStock(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		option,
		FStockSysNo,
		inReserve,
		errmsg,
		errorCode,
		errorMsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestGetStockByIds()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(8887);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(8887);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	std::set<uint64_t > IDList;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::vector<erp::storage::ddo::CStockDdo > StockList;
	std::string outReserve = "";		
	CStorageDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.GetStockByIds(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		IDList,
		inReserve,
		errmsg,
		StockList,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestGetStockList()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(1);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(1);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	erp::storage::ddo::CStockFilterDdo StockFilter;
	std::string inReserve = "";		
	std::string errmsg = "";		
	uint32_t total = 0;
	std::vector<erp::storage::ddo::CStockDdo > StockList;
	std::string outReserve = "";		
	CStorageDaoStub4Web oStub;

	//mork
	StockFilter.dwFStatus = 1;
	StockFilter.dwPageSize = 5;
	StockFilter.dwPage = 1;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.GetStockList(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		StockFilter,
		inReserve,
		errmsg,
		total,
		StockList,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestUpdateStock()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(1);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(1);
	std::string machineKey = "123";
	std::string source = "123";
	uint32_t sceneId = 123;
	uint32_t option = 0;
	erp::storage::ddo::CStockDdo StockInfo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	CStorageDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.UpdateStock(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		option,
		StockInfo,
		inReserve,
		errmsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
//测试主函数
int main(int argc, char** argv)
{
	//
	//测试主流程
	// 开发人员可以根据业务需要进行顺序的调整，以期达到更好的测试效果
	// 比如，可以按照插入、选择、修改、选择、删除、选择 顺序进行处理
	//
	Init();
	//TestAddStock();
	//TestDeleteStock();
	//TestGetStockByIds();
	TestGetStockList();
	//TestUpdateStock();
	return 0;
}
